const Mongoose = require('mongoose')

// 定义一个模型中的字段
const schema = new Mongoose.Schema({
  name: { type: String },
  avatar: { type: String },
  banner: { type: String },
  title: { type: String },
  categories: [{ type: Mongoose.Schema.Types.ObjectId, ref: 'Category' }],
  scores: {
    difficult: { type: Number },
    skills: { type: Number },
    attack: { type: Number },
    survive: { type: Number },
  },
  skills: [
    {
      name: { type: String },
      icon: { type: String },
      delay: { type: String },
      cost: { type: String },
      description: { type: String },
      tips: { type: String },
    }
  ],
  items1: [{ type: Mongoose.Schema.Types.ObjectId, ref: 'Item' }],
  items2: [{ type: Mongoose.Schema.Types.ObjectId, ref: 'Item' }],
  usageTips: { type: String },
  battleTips: { type: String },
  teamTips: { type: String },
  partners: [{
    hero: { type: Mongoose.Schema.Types.ObjectId, ref: 'Hero' },
    description: { type: String }
  }]
})

// 导出数据库模型 根据schema定义的方式创建模型 相当于SQL中的表
module.exports = Mongoose.model('Hero', schema, 'heroes')